package home

import (
	// "fmt"

	"gitee.com/chenrh/finego/app"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
)

// IndexController 首页控制器
type IndexController struct {
	// Optionally: context is auto-binded by Iris on each request,
	// remember that on each incoming request iris creates a new UserController each time,
	// so all fields are request-scoped by-default, only dependency injection is able to set
	// custom fields like the Service which is the same for all requests (static binding).
	Ctx iris.Context
}

// BeforeActivation called once, before the controller adapted to the main application
// and of course before the server ran.
// After version 9 you can also add custom routes for a specific controller's methods.
// Here you can register custom method's handlers
// use the standard router with `ca.Router` to do something that you can do without mvc as well,
// and add dependencies that will be binded to a controller's fields or method function's input arguments.
func (c *IndexController) BeforeActivation(b mvc.BeforeActivation) {
	b.Handle("GET", "/about-us", "AboutUs")
	b.Handle("GET", "/resume", "MyResume")
}

// Get 首页
func (c *IndexController) Get() mvc.Result {
	c.Ctx.ViewLayout(iris.NoLayout)
	return mvc.View{
		Name: "index.html",
		Data: iris.Map{
			"Title": app.AppConfig.AppName,
		},
	}
}

// Index 首页
func (c *IndexController) Index() mvc.Result {
	c.Ctx.ViewLayout(iris.NoLayout)
	return mvc.View{
		Name: "index.html",
		Data: iris.Map{"Title": "首页"},
	}
}

// AboutUs 关于我们
func (c *IndexController) AboutUs() mvc.Result {
	return mvc.View{
		Name: "about-us.html",
		Data: iris.Map{"Title": "关于我们"},
	}
}

// MyResume 我的简历
func (c *IndexController) MyResume() mvc.Result {
	c.Ctx.ViewLayout(iris.NoLayout)
	return mvc.View{
		Name: "resume.html",
	}
}
